#include "stdafx.h"

#include "LinkList.h"

#ifdef RUN_2_4



void resortLink(LinkList& ll, int k)
{
	if(!ll.head)
		return;
	Node *head1 = NULL, *head2 = NULL;
	Node *pt1 = head1, *pt2 = head2;

	Node *pt = ll.head; 
	Node *tmp;
	while(pt)
	{
		if(pt->data < k)
		{			
			if(head1)
			{
				pt1->next = pt;
				pt1 = pt;
			}
			else
			{
				head1 = pt;
				pt1 = pt;
			}

		}
		else
		{
			if(head2)
			{
				pt2->next = pt;
				pt2 = pt;
			}
			else
			{
				head2 = pt;
				pt2 = pt;
			}
		}
		pt = pt->next;
	}

	if(head1 == NULL)
	{
		ll.head = head2;
		pt2->next = NULL;
	}
	else
	{
		pt1->next = head2;
		if(pt2)
			pt2->next = NULL;
		ll.head = head1;
	}



	

}

int main()
{
	LinkList ll;

	ll.appendToTail(5);
	ll.appendToTail(5);
	ll.appendToTail(5);
	ll.appendToTail(3);
	ll.appendToTail(3);
	ll.appendToTail(3);

	//ll.appendToTail(6);
	//ll.appendToTail(7);
	//ll.appendToTail(8);
	//ll.appendToTail(1);
	//ll.appendToTail(2);
	//ll.appendToTail(3);
	//ll.appendToTail(4);
	//ll.appendToTail(9);
	ll.print();

	resortLink(ll, 4);

	cout << "Transfer" << endl;
	
	ll.print();
	getchar();
}

#endif